<template>
  <Footer :class="prefixCls" v-if="getShowLayoutFooter" ref="footerRef">
    <div :class="`${prefixCls}__links`">
      <a @click="openWindow(SITE_URL)">{{ t("layout.footer.onlinePreview") }}</a>

      <Icon
        icon="i-ant-design:github-filled"
        @click="openWindow(GITHUB_URL)"
        :class="`${prefixCls}__github`"
      />

      <a @click="openWindow(DOC_URL)">{{ t("layout.footer.onlineDocument") }}</a>
    </div>
    <div :class="`${prefixCls}__links`">
      <span>Copyright © 2022 - 2023 ICP备案/许可证号: </span>
      <a href="https://beian.miit.gov.cn/" target="_blank">{{ publicConfig.sysCopyright.icp }}</a>
    </div>
  </Footer>
</template>

<script lang="ts">
  import { computed, defineComponent, unref, ref } from "vue"
  import { Layout } from "ant-design-vue"

  import { Icon } from '/@/components/Icon';
  import { DOC_URL, GITHUB_URL, SITE_URL } from "/@/settings/siteSetting"
  import { openWindow } from "/@/utils"
  import * as appCache from "/@/utils/cache/module"
  import { useI18n } from "/@/hooks/web/useI18n"
  import { useRootSetting } from "/@/hooks/setting/useRootSetting"
  import { useRouter } from "vue-router"
  import { useDesign } from "/@/hooks/web/useDesign"
  import { useLayoutHeight } from "../content/useContentViewHeight"

  export default defineComponent({
    name: "LayoutFooter",
    components: { Footer: Layout.Footer, Icon },
    setup() {
      const { t } = useI18n()
      const { getShowFooter } = useRootSetting()
      const { currentRoute } = useRouter()
      const { prefixCls } = useDesign("layout-footer")
      const publicConfig = appCache.getPublicConfig()

      const footerRef = ref<ComponentRef>(null)
      const { setFooterHeight } = useLayoutHeight()

      const getShowLayoutFooter = computed(() => {
        if (unref(getShowFooter)) {
          const footerEl = unref(footerRef)?.$el
          setFooterHeight(footerEl?.offsetHeight || 0)
        } else {
          setFooterHeight(0)
        }
        return unref(getShowFooter) && !unref(currentRoute).meta?.hiddenFooter
      })

      return {
        publicConfig,
        getShowLayoutFooter,
        prefixCls,
        t,
        DOC_URL,
        GITHUB_URL,
        SITE_URL,
        openWindow,
        footerRef,
      }
    },
  })
</script>
<style lang="less" scoped>
  @prefix-cls: ~"@{namespace}-layout-footer";

  // @normal-color: rgba(0, 0, 0, 0.45);
  @footer-normal-color: rgb(115, 119, 122);

  @hover-color: #1890ff;

  .@{prefix-cls} {
    color: @footer-normal-color;
    text-align: center;

    &__links {
      margin-bottom: 8px;

      a {
        color: @footer-normal-color;

        &:hover {
          color: @hover-color;
        }
      }
    }

    &__github {
      margin: 0 30px;

      &:hover {
        color: @hover-color;
      }
    }
  }
</style>
